/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.bingoogolapple.badgeview.demo;

import cn.bingoogolapple.badgeview.BGABadgeViewUtil;
import cn.bingoogolapple.badgeview.TextUtils;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.agp.components.AttrSet;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.Text;
import ohos.app.Context;
import ohos.media.image.PixelMap;
import org.junit.Assert;
import org.junit.Test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
 * ExampleOhosTest
 *
 * @since 2021-04-21
 */
public class ExampleOhosTest {
    /**
     * testBundleName
     */
    @Test
    public void testBundleName() {
        final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName();
        assertEquals("cn.bingoogolapple.badgeview.demo", actualBundleName);
    }

    /**
     * isTextValue
     */
    @Test
    public void isTextValue() {
        boolean isValue = TextUtils.isEmpty("");
        Assert.assertTrue(isValue);
    }

    /**
     * isBitmapFromView
     */
    @Test
    public void isBitmapFromView() {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getCurrentTopAbility().getContext();
        Text text = new Text(context);
        ComponentContainer.LayoutConfig layoutConfig = new ComponentContainer.LayoutConfig();
        layoutConfig.height = 50;
        layoutConfig.width = 50;
        text.setLayoutConfig(layoutConfig);
        text.setText("Hello");
        PixelMap pixelMap = BGABadgeViewUtil.getBitmapFromView(text);
        assertNotNull(pixelMap);
    }

    /**
     * testDp2px
     */
    @Test
    public void testDp2px() {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getCurrentTopAbility().getContext();
        int value = BGABadgeViewUtil.dp2px(context,20);
        assertNotNull(value);
    }

    /**
     * testSp2px
     */
    @Test
    public void testSp2px() {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getCurrentTopAbility().getContext();
        int value = BGABadgeViewUtil.sp2px(context,10);
        assertNotNull(value);
    }

    /**
     * testGetStringValue
     */
    @Test
    public void testGetStringValue(){
        try {
            Class attrUtil = Class.forName("cn.bingoogolapple.badgeview");
            Method getStringValue = attrUtil.getMethod("getStringValue", AttrSet.class, String.class, String.class);
            Object object = attrUtil.getConstructor().newInstance();
            getStringValue.invoke(object,"key","value");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }


}